import axios, { url } from '.';

export const login = async (data) => {
    let res = await axios({
        method: "post",
        url: url + "/users/loginUser",
        data
    });
    return res.data;
}

export const reg = async (data) => {
    let res = await axios({
        method: "post",
        url: url + "/users/reg",
        data
    })
    return res.data;
}
// 验证
export const usernameExist = async (data) => {
    let res = await axios({
        method: 'post',
        url: url + '/users/usernameExist',
        data
    })
    return res.data;
}

export const getAll = async (data) => {
    let res = await axios({
        method: "get",
        url: url + '/users/find',
        params: data
    });
    return res.data;
}

export const addUser = async (data) => {
    let res = await axios({
        method: "post",
        url: url + '/users',
        data
    })
    return res.data;
}

export const getToken = async (data) => {
    let res = await axios({
        method: "get",
        url: url + "/getToken",

    });
    return res.data;
}

export const getId = async (data) => {
    let res = await axios({
        method: "get",
        url: url + '/users/' + data.id,
        params: data
    })
    return res.data;
}

export const updateUser = async (data) => {
    console.log(data);
    let res = await axios({
        method: "put",
        url: url + '/users/' + data.id,
        data
    })
    return res.data;

}
export const deleteUser = async (data) => {
    let res = await axios({
        method: "delete",
        url: url + '/users/' + data.id,

    })
    return res.data;
}